<template>
  <transition :name="isNext? 'big': 'small'">
    <div
      class="swiper-item"
      v-show="show"
    >
      <slot></slot>
    </div>
  </transition>
</template>

<script>
export default {
  data() {
    return {}
  },
  computed: {
    index() {
      return this.$parent.$children.findIndex(item => item === this)
    },
    show() {
      return this.index === this.$parent.currentSwiper
    },
    isNext() {
      return (
        this.index < this.$parent.currentSwiper ||
        (this.index === this.$parent.swipers.length - 1 && this.$parent.currentSwiper === 0)
      )
    }
  },
  created() {
    this.$parent.swipers.push(this)
  }
}
</script>

<style lang="less" scoped>
.swiper-item {
  height: 100%;
  width: 100%;
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: center center;
}
</style>

<style lang="less">
&.big-enter-active,
&.big-leave-active {
  transition: all 0.5s;
}
&.big-leave-active {
  z-index: 3;
  opacity: 0;
  transform: scale(1.3);
}
&.small-enter-active,
&.small-leave-active {
  transition: all 0.5s;
}
&.small-leave-active {
  z-index: 3;
  opacity: 0;
  transform: scale(0.8);
}
</style>
